<?php

class anexoActions extends sfActions
{

	public function executeShowAddOn(sfWebRequest $request)
	{
		return $this->showFile(sfConfig::get('anexo_dir') . $request->getParameter('file'));
	}

	public function executeShowCurriculum(sfWebRequest $request)
	{
		return $this->showFile(sfConfig::get('curriculo_dir') . $request->getParameter('file'));
	}

	public function executeShowImage(sfWebRequest $request)
	{
		$file = sfConfig::get('homologacion_dir') . $request->getParameter('file');

		$this->forward404Unless(file_exists($file), 'El archivo no existe');

		$this->getResponse()->clearHttpHeaders();
		$this->getResponse()->setHttpHeader('Content-Length', filesize($file));
		$this->getResponse()->setContentType(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file));
		$this->getResponse()->sendHttpHeaders();
		$this->getResponse()->setContent(readfile($file));

		return sfView::NONE; 
	}

	private function showFile($file)
	{
		$this->forward404Unless(file_exists($file), 'El archivo no existe');

		$this->getResponse()->clearHttpHeaders();
		$this->getResponse()->setHttpHeader('Pragma: public', true);
		$this->getResponse()->setContentType('application/pdf');
		$this->getResponse()->sendHttpHeaders();
		$this->getResponse()->setContent(readfile($file)); //FIXME: esto carga el archivo en memoria
		return sfView::NONE;
	}

}
